package web.stu.model.enums;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;

/**
 * 用户角色枚举
 */
@Getter
public enum UserRoleEnum {
    STUDENT("学生", 0),
    TEACHER("教师", 1),
    ADMIN("管理员", 2);

    private String key;
    private Integer value;

    UserRoleEnum(String key, Integer value) {
        this.key = key;
        this.value = value;
    }

    /**
     * 根据 key 获取
     *
     * @param key
     * @return
     */
    public static UserRoleEnum getEnumByValue(String key) {
        if (StrUtil.isEmpty(key)) {
            return null;
        }
        for (UserRoleEnum anEnum : UserRoleEnum.values()) {
            if (anEnum.key.equals(key)) {
                return anEnum;
            }
        }
        return null;
    }


}
